//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "CumulativePoissonDistribution.h"
using namespace Cephei::QL::Math::Distributions;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Distributions::CCumulativePoissonDistribution::CCumulativePoissonDistribution (Double mu) 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phCumulativePoissonDistribution = NULL;
#endif
        QuantLib::Real _mu = (QuantLib::Real)ValueHelper::Convert (mu);
        _ppCumulativePoissonDistribution = new boost::shared_ptr<QuantLib::CumulativePoissonDistribution> (new QuantLib::CumulativePoissonDistribution ( _mu ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Distributions::CCumulativePoissonDistribution::CCumulativePoissonDistribution (boost::shared_ptr<QuantLib::CumulativePoissonDistribution>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phCumulativePoissonDistribution = NULL;
#endif
	_ppCumulativePoissonDistribution = &childNative;
    
}
Cephei::QL::Math::Distributions::CCumulativePoissonDistribution::CCumulativePoissonDistribution (QuantLib::CumulativePoissonDistribution& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phCumulativePoissonDistribution = NULL;
#endif
	_ppCumulativePoissonDistribution = new boost::shared_ptr<QuantLib::CumulativePoissonDistribution> (&childNative);
    
    _CumulativePoissonDistributionOwner = owner;
    
}

Cephei::QL::Math::Distributions::CCumulativePoissonDistribution::CCumulativePoissonDistribution (CCumulativePoissonDistribution^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phCumulativePoissonDistribution = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppCumulativePoissonDistribution = new boost::shared_ptr<QuantLib::CumulativePoissonDistribution> (copy->GetShared());
        
    }
}
Cephei::QL::Math::Distributions::CCumulativePoissonDistribution::CCumulativePoissonDistribution (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phCumulativePoissonDistribution = NULL;
#endif
	if (!t->IsSubclassOf(CCumulativePoissonDistribution::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Distributions::CCumulativePoissonDistribution::CCumulativePoissonDistribution (QuantLib::Handle<QuantLib::CumulativePoissonDistribution>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phCumulativePoissonDistribution = &childNative;
	_ppCumulativePoissonDistribution = &static_cast<boost::shared_ptr<QuantLib::CumulativePoissonDistribution>>(childNative.currentLink());
    
    _CumulativePoissonDistributionOwner = owner;
}
Cephei::QL::Math::Distributions::CCumulativePoissonDistribution::CCumulativePoissonDistribution (QuantLib::Handle<QuantLib::CumulativePoissonDistribution> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phCumulativePoissonDistribution = &childNative;
	_ppCumulativePoissonDistribution = &static_cast<boost::shared_ptr<QuantLib::CumulativePoissonDistribution>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Distributions::CCumulativePoissonDistribution::CCumulativePoissonDistribution (QuantLib::CumulativePoissonDistribution childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phCumulativePoissonDistribution = NULL;
#endif
	_ppCumulativePoissonDistribution = new boost::shared_ptr<QuantLib::CumulativePoissonDistribution> (new QuantLib::CumulativePoissonDistribution (childNative));
    
}
#endif

Cephei::QL::Math::Distributions::CCumulativePoissonDistribution::~CCumulativePoissonDistribution ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppCumulativePoissonDistribution != NULL)
    {
	    delete _ppCumulativePoissonDistribution;
        _ppCumulativePoissonDistribution = NULL;
    }
}
Cephei::QL::Math::Distributions::CCumulativePoissonDistribution::!CCumulativePoissonDistribution ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppCumulativePoissonDistribution != NULL)
    {
	    delete _ppCumulativePoissonDistribution;
    }
}
QuantLib::CumulativePoissonDistribution& Cephei::QL::Math::Distributions::CCumulativePoissonDistribution::GetReference ()
{
    if (_ppCumulativePoissonDistribution == NULL) throw gcnew NativeNullException ();
	return **_ppCumulativePoissonDistribution;
}
boost::shared_ptr<QuantLib::CumulativePoissonDistribution>& Cephei::QL::Math::Distributions::CCumulativePoissonDistribution::GetShared ()
{
    if (_ppCumulativePoissonDistribution == NULL) throw gcnew NativeNullException ();
	return *_ppCumulativePoissonDistribution;
}
QuantLib::CumulativePoissonDistribution* Cephei::QL::Math::Distributions::CCumulativePoissonDistribution::GetPointer ()
{
    if (_ppCumulativePoissonDistribution == NULL) throw gcnew NativeNullException ();
	return &**_ppCumulativePoissonDistribution;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::CumulativePoissonDistribution>& Cephei::QL::Math::Distributions::CCumulativePoissonDistribution::GetHandle ()
{
	if (_phCumulativePoissonDistribution == NULL)
	{
		_phCumulativePoissonDistribution = new Handle<QuantLib::CumulativePoissonDistribution> (*_ppCumulativePoissonDistribution);
	}
	return *_phCumulativePoissonDistribution;
}
#endif
bool Cephei::QL::Math::Distributions::CCumulativePoissonDistribution::HasNative () 
{
	return (_ppCumulativePoissonDistribution != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Distributions::ICumulativePoissonDistribution^ Cephei::QL::Math::Distributions::CCumulativePoissonDistribution_Factory::Create (Double mu)
{
    return gcnew CCumulativePoissonDistribution ( mu);
}
